package com.udata.client.service.impl;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.udata.server.dao.impl.TiebaExpDaoImpl;
import com.udata.shared.exception.OperationException;

public class JsonServlet extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response) {
    response.setContentType("application/json");
    response.setContentType("text/plain;charset=utf-8");
    try {
      request.setCharacterEncoding("utf-8");
    } catch (UnsupportedEncodingException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    String json = null;
	try {
		json = TiebaExpDaoImpl.getinstance().getJsonData("大杰西");
		} catch (OperationException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
   
    // Get the printwriter object from response to write the required json
    // object to the output stream
    PrintWriter out;

    try {
      String qs = request.getParameter("callback");
      out = response.getWriter();
      out.print(qs + "("+json+")");
      out.flush();
      out.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    // Assuming your json object is **jsonObject**, perform the following, it
    // will return your json object

  }

}
